package Dao;

import Entity.Account;
import org.hibernate.SQLQuery;
import org.springframework.orm.hibernate3.HibernateTemplate;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import java.util.List;

public class AccountDaoImpl extends HibernateDaoSupport implements AccountDao {
    @Override
    public void updateAccount(Account account) {
       super.getHibernateTemplate().update(account);
    }

    @Override
    public List<Account> accountList() {

        List<Account> accountList = getHibernateTemplate().getSessionFactory().openSession().createSQLQuery("select * from account").addEntity(Account.class).list();
        return  accountList;

    }

    @Override
    public Account getAccountById(int id) {
        SQLQuery sqlQuery = getHibernateTemplate().getSessionFactory().openSession().createSQLQuery("select * from account a where a.accountid = ? ").addEntity(Account.class);
       Account account = (Account) sqlQuery.setInteger(0,id).uniqueResult();
       return account;
    }
}
